<body>
<audio></audio>
<video></video>
<script>
    window.addEventListener('load', function () {
        var windowOpener = window.opener;
        var isAudioLoaded = false;
        var isVideoLoaded = false;
        function checkTestCompletion() {
          if (isAudioLoaded && isVideoLoaded && windowOpener) {
            windowOpener.postMessage('done', '*');
          }
        }

        // Assigning via JavaScript after 'load' rather than direclty in the
        // markup in order to avoid the console's flaky "what line am I on?"
        // autodetection.
        var audioElement = document.querySelector('audio');
        audioElement.src = "http://example.test:8080/resources/test.mp4";
        audioElement.addEventListener("loadstart", function(event) {
          isAudioLoaded = true;
          checkTestCompletion();
        });

        var videoElement = document.querySelector('video');
        videoElement.src = "http://example.test:8080/resources/test.mp4";
        videoElement.addEventListener("loadstart", function(event) {
          isVideoLoaded = true;
          checkTestCompletion();
        });
    });
</script>
</body>
